package com.hsd.mapper.impl;

import com.hsd.mapper.ILogDao;
import com.hsd.entity.Log;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ILogDaoImpl implements ILogDao {
    @Autowired
    private SessionFactory sessionFactory;

    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }

    @Override
    public int insertLog(Log log) {
        Session session = getSession();
        session.flush();
        session.clear();
        Object merge = session.save(log);
        return (int) merge;
    }

    @Override
    public List<Log> selectByAcc(String acc) {
        String hql = "from Log log where log.acc = :a";
        List<Log> list = getSession().createQuery(hql).setParameter("a", acc).list();
        return list;
    }
}
